<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('漫画爬虫列表')"/>
    <!--select 下拉框-->
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>漫画：</label>
                            <!--<input type="text" name="nameId"/>-->
                            <select name="nameId" class="form-control m-b" th:with="type=${MhNameDataAll}">
                                <option value=""></option>
                                <option th:each="map : ${type}" th:text="${map.value}" th:value="${map.key}"></option>
                            </select>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="delFlag" class="form-control m-b">
                                <option value=""></option>
                                <option  value="0">启用</option>
                                <option  value="2">停用</option>
                            </select>
                        </li>
                        <li>
                            <label>爬取：</label>
                            <select name="webType" class="form-control m-b" th:with="type=${@all.toAll()}">
                                <option value=""></option>
                                <option th:each="map : ${type}" th:text="${map.key}" th:value="${map.value}"></option>
                            </select>

                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="manhua:climb:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="manhua:climb:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="manhua:climb:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="manhua:climb:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<!--select 下拉框-->
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">

    var editFlag = [[${@permission.hasPermi('manhua:climb:edit')}]];

    var removeFlag = [[${@permission.hasPermi('manhua:climb:remove')}]];

    let MhNameDataAll = [[${MhNameDataAll}]];

    var prefix = ctx + "manhua/climb";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "漫画爬虫",
            columns: [{
                checkbox: false
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'nameId',
                    title: '漫画',
                    formatter: function (value, row, index) {
                        return $.common.reale({value:MhNameDataAll[value], numder: 2});
                    }
                },
                {
                    field: 'webType',
                    title: '爬取类型',
                    formatter: function (value, row, index) {
                        return $.common.reale({value: value, numder: 3});
                    }
                },
                {
                    field: 'network',
                    title: '内链外链',
                    formatter: function (value, row, index) {
                        return value === '1' ? $.common.reale({value: '内链', numder: 3}) : $.common.reale({value: '外链', numder: 2});
                    }
                },
                {
                    field: 'webUrl',
                    title: '网页地址',
                    formatter: function (value, row, index) {
                        return $.common.reale({value: value, numder: 1});
                    }
                },
                {
                    field: 'delFlag',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return value == 0 ? $.common.reale({value: "启用", numder: 1}) : $.common.reale({
                            value: "停用",
                            numder: 4
                        })
                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value,null,"open");//传值 长度不传添加所有字节
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        row.delFlag == 0?actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="staus(\'' + row.id + '\',0)"><i></i>停用</a> ')
                            :actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="staus(\'' + row.id + '\',2)"><i></i>启用</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*修改状态*/
    let staus = (id, numder) => {
        if (numder == 0) {
            $.modal.confirm("确认要停用吗?", function () {
                $.operate.submit(prefix + "/edit", "post", "json", {id: id, delFlag: 2});
            });

        } else {
            $.modal.confirm("确认要启用吗?", function () {
                $.operate.submit(prefix + "/edit", "post", "json", {id: id, delFlag: 0});
            });
        }
    }
</script>
</body>
</html>
